﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = openFileDialog1.ShowDialog();//弹出对话框
                if (dialogResult == DialogResult.OK)//确定
                {
                    //用vs数组存储选中的文件的文件名
                    string[] vs = openFileDialog1.FileNames;
                    //创建路径
                    string path = System.Windows.Forms.Application.StartupPath + "\\Data\\";
                    //判断该路径下文件夹是否存在，不存在的情况下新建文件夹
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    //创建目标文本文档
                    string postPath = path + "target" + ".txt";
                    FileStream target = new FileStream(postPath, FileMode.Create);
                    FileStream[] fileStreams = new FileStream[vs.Length];
                    int b;
                    for(int i = 0; i < vs.Length; i++)
                    {
                        fileStreams[i] = new FileStream(vs[i], FileMode.Open);
                        while ((b = fileStreams[i].ReadByte()) != -1)
                            target.WriteByte((byte)b);
                    }
                    label1.Text += "已经在bin\\Debug\\Data目录下生成了目标文本文档！\r\n请关闭此窗口后查看。";
                }
            }catch(Exception a)
            {
                MessageBox.Show(a.Message);
            }
            
        }
    }
}
